package sandboxGUI;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;




public class MainGUI {

	
	//Constructor Passed Variables to this class
	private JFrame frameMaster = new JFrame();
	private JPanel mainCard = new JPanel();
	
	
	
	//CardLayout Variables
	final static String MAIN_WINDOW = "CMNC Main";
	
		
	//JMenu Items
	private JMenuBar menuBar;
	private JMenu mnFile;
	private JMenuItem mntmSetup;
	private JMenuItem mntmLogout;
	private JMenuItem mntmAbout;
	private JMenuItem mntmExit;
	private JMenu mnHelp;
	
	//Setup Window Variables - used by a MainGUI instance to get COM Settings
	SetupGUI setupWindow = new SetupGUI();
	

	SandboxWindowGUI masterWindow;
	PasswordGUI passwordWindow;

	
	
	//Constructor
	public MainGUI(SandboxWindowGUI window) {
		masterWindow = window;
		frameMaster = masterWindow.getFrame();
		menuBar = masterWindow.getMenuBar();
		mainCard = masterWindow.getMainCard();
		buildMainGUI();
	}//end MainGUI() constructor
	
		
	private void buildMainGUI() {

		//created the Main GUI
		frameMaster.setTitle("CMNC Main");//Set frame title
		//http://www.java2s.com/Tutorial/Java/0240__Swing/ResizingandpositioningaJFrame.htm
		frameMaster.setSize(1024, 768);//use this instead of set bounds in order to avoid having to set the starting x and y coordinates
		menuBar.setVisible(true);//show the menu bar		
		frameMaster.setLocationRelativeTo(null);//allows the frame to be in the center by default
		mainCard.setLayout(null);
		
		//Build Menu Bar
		buildMenuBar();
		
		
		//add Main GUI elements here		
	}//buildMainGUI()
	
	
	private void buildMenuBar() {
		//Create Menu Bar
		frameMaster.setJMenuBar(menuBar);
		mnFile = new JMenu("File");
		menuBar.add(mnFile);
		
		mntmSetup = new JMenuItem("Setup");
		mnFile.add(mntmSetup);
		
		mntmSetup.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				//Create new pop up window
				setupWindow.buildSetupWindow();

			}//end actionPerformed
		});//end addActionListener
		
		mntmLogout = new JMenuItem("Logout");
		mnFile.add(mntmLogout);
		
		mntmLogout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				masterWindow.hideFrame();//hide master window
				masterWindow.passwordWindow.seeFrame();//show password window
			}//end actionPerformed
		});//end addActionListener
				
		
		mntmExit = new JMenuItem("Exit");
		mnFile.add(mntmExit);
		
		mntmExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				//Exit Program
				exitProgram();
			}//end actionPerformed
		});//end addActionListener
		
		mnHelp = new JMenu("Help");
		menuBar.add(mnHelp);
		
		mntmAbout = new JMenuItem("About");
		mnHelp.add(mntmAbout);
		
		
	}//end buildMenuBar()
	
	private void exitProgram() {
		//Exit the program
		System.exit(0);
	}
	
}
